import instance from '@/utils/request'
import store from '@/store'

// 获取用户地址
export const getUserAddress = () => {
  const token = store.getters.isLogin
  if (!token) return
  return instance({
    url: '/address/list',
    headers: {
      'Access-Token': token,
      platform: 'H5'
    }
  })
}

// 添加收货地址
export const addUserAddress = (name, phone, region) => {
  const token = store.getters.isLogin
  return instance({
    url: '/address/add',
    method: 'POST',
    headers: {
      'Access-Token': token,
      platform: 'H5'
    },
    data: {
      form: {
        name,
        phone,
        region,
        detail: '北京路1号楼8888室'
      }
    }
  })
}

// 设置默认地址
export const setDefaultAddress = (addressId) => {
  const token = store.getters.isLogin
  return instance({
    url: '/address/setDefault',
    method: 'POST',
    headers: {
      'Access-Token': token,
      platform: 'H5'
    },
    data: {
      addressId
    }
  })
}

// 默认收货地址id
export const getDefaultAddressId = () => {
  const token = store.getters.isLogin
  return instance({
    url: '/address/defaultId',
    headers: {
      'Access-Token': token,
      platform: 'H5'
    }
  })
}
